//
//  MWUserManager.m
//  XiRan-iOS
//
//  Created by Richfit on 2019/10/22.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWUserManager.h"

@interface MWUserManager ()

@end

@implementation MWUserManager

+ (instancetype)manager {
    static MWUserManager *manager;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[MWUserManager alloc] init];
    });
    return manager;
}

- (BOOL)isLogin {
    if (_user) {
        return YES;
    } else {
        return NO;
    }
}

- (void)saveUser {
    NSData *data = [NSKeyedArchiver archivedDataWithRootObject:_user];
    NSUserDefaults *userDetaults = [NSUserDefaults standardUserDefaults];
    [userDetaults setObject:data forKey:@"MWUser"];
    [userDetaults synchronize];
}

- (void)loadUser {
    NSData *data = [[NSUserDefaults standardUserDefaults] objectForKey:@"MWUser"];
    _user  = [NSKeyedUnarchiver unarchiveObjectWithData:data];
}

- (void)clearUser {
    NSUserDefaults *userDetaults = [NSUserDefaults standardUserDefaults];
    [userDetaults removeObjectForKey:@"MWUser"];
    [userDetaults synchronize];
}

@end
